package com.ycz.algorithm.utils.queue;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @author yancz
 * @ClassName DueueUtil
 * @description: TODO
 * @date 2024-11-28 10:52:27
 * @version: 1.0
 */
public class DequeUtil {

    public static void main(String[] args) {
        Deque<Integer> deque = new LinkedList<>();
        // 元素入队尾
        deque.offerLast(1);
        deque.offerLast(2);
        deque.offerLast(3);
        // 元素入队首
        deque.offerFirst(4);
        deque.offerFirst(5);
        int first = deque.peekFirst(); // 访问队首
        int last = deque.peekLast(); // 访问队尾
        for(int i:deque) {
            System.out.print(i + "\t");
        }
        System.out.println();
        System.out.println("队首元素：" + first);
        System.out.println("队尾元素：" + last);
        // 元素出队
        System.out.println("出队元素：" + deque.pollFirst()); // 队首出队
        System.out.println("出队元素：" + deque.pollLast()); // 队尾出队
        System.out.println("队列长度：" + deque.size());
        System.out.println("队首元素：" + deque.peekFirst());
        System.out.println("队尾元素：" + deque.peekLast());
        System.out.println("队空？" + deque.isEmpty());
    }

}
